package cn.cscb.mms.server.service.impl;

import cn.cscb.mms.common.exception.SomeBusinessException;
import cn.cscb.mms.pojo.entity.Customer;
import cn.cscb.mms.server.mapper.CustomerMapper;
import cn.cscb.mms.server.service.CustomerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 测试用接口实现，无需扩展
 *
 * @author Gao Yipeng
 */
@Service("customerService")
public class CustomerServiceImpl implements CustomerService {

    @Resource(name = "customerMapper")
    private CustomerMapper customerMapper;

    /**
     * 通过id获取客户信息
     *
     * @param id 客户逻辑id
     * @return 客户信息
     */
    @Override
    public Customer getCustomerByIdTest01(Integer id) {
        return customerMapper.getByIdTest01(id);
    }

    /**
     * 通过id获取客户信息
     *
     * @param id 客户逻辑id
     * @return 客户信息
     */
    @Override
    public Customer getCustomerByIdTest02(Integer id) {
        return customerMapper.getByIdTest02(id);
    }

    /**
     * 查询所有用户，分页返回
     *
     * @param page 当前页码
     * @param row  每页行数
     * @return 分页结果
     */
    @Override
    public IPage<Customer> getCustomerPages(Integer page, Integer row) {
        Page<Customer> customerPage = new Page<>(page, row);
        return customerMapper.getPages(customerPage);
    }

    /**
     * 测试遭遇业务异常的场景
     *
     * @return 客户信息（无意义）
     */
    @Override
    public Customer testEncounterException() {
        if (true) {
            throw new SomeBusinessException("这是一个测试用异常信息");
        }
        return null;
    }
}
